#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct ok{
	int a,b;
	bool operator <(const ok &A) const{return b==A.b?a<A.a:b<A.b;}
}a[N];
int n,minn[2][N];
long long ans=1e18;
int main()
{
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].a,&a[i].b);
	sort(a+1,a+n+1);
	minn[0][0]=minn[1][n+1]=INT_MAX;
	for(int i=1;i<=n;i++)
		minn[0][i]=min(a[i].a,minn[0][i-1]);
	for(int i=n;i;i--)
		minn[1][i]=min(a[i].a+a[i].b,minn[1][i+1]);
	for(int i=2;i<n;i++)
		ans=min(ans,1ll*minn[0][i-1]+a[i].a+a[i].b+minn[1][i+1]);
	printf("%lld\n",ans);
	fclose(stdin);fclose(stdout);
	return 0;
}
